<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/prettyphoto.css" rel="stylesheet" />
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.mselect.js?"></script>
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.prettyphoto.js"></script>
<script type="text/javascript">
$(function(){
	$("a[rel^='pretty_photo']").prettyPhoto({theme:'facebook'});
	$(".datepicker").datepicker({dateFormat:'yy-mm-dd',changeMonth:true});
	$(".warehouse_notes_icon").colorbox({width:"50%", height:"50%", iframe:true});
	var purchase_categories_data = <?=$purchase_categories?>;
	$(document).mselect(purchase_categories_data, 'product_categories_id','product_categories_id', "<?=isset($_GET['product_categories_id'])?$_GET['product_categories_id']:0?>");
	$(".self_status").mouseover(function(){
		$(this).next().show();
	}).mouseout(function(){
		$(this).next().hide();
	});
	$(".more_status").mouseover(function(){
		$(this).show();
	}).mouseout(function(){
		$(this).hide();
	});
	$("#request_download").click(function(){
		var current_tag = $(this);
		$(this).attr("disabled", true);
		var url_arr_json = current_tag.prev().val();
		$.ajax({
			url: "<?=url('DataCenter::Warehouse/StockAnalysisDownload')?>&url_arr_json=" + url_arr_json,
			type: "get",
			dataType: "json",
			beforeSend:
				function()
				{
					$("#download_loading_img").html("<img src='<?=Q::ini('custom_system/base_url')?>img/loading.gif' />");
				},
			error:
				function()
				{
					$("#download_loading_img").html("系统异常，导出失败！");
				},
			success:
				function(ret)
				{
					$("#download_loading_img").html("");
					if (ret['ack'] == 'success')
					{
						current_tag.parent().append("<a href='"+ret['url']+"'>下载文件</a>");
					}
					else
					{
						current_tag.parent().append("请求失败");
					}
				}
		})
	});
	$("#refresh_status").click(function(){
		$("#refresh_status").attr("disabled", true);
		$.ajax({
			url: "<?=url('DataCenter::Warehouse/UpdateProductSalesStatusAllArtificial')?>",
			type: "get",
			dateType: "json",
			beforeSend:
				function(){
					$("#loading_img").html("<img src='<?=Q::ini('custom_system/base_url')?>img/loading.gif' />");
				},
			success:
				function()
				{
					$("#loading_img").html("");
				}
		});
	});
	
	$(".change_sales_status_click").click(function(){
		var current_tag = $(this);
		var data = current_tag.next().val();
		$.ajax({
			url: "<?=url('DataCenter::Warehouse/UpdateProductSalesStatusSingle')?>&data=" + data,
			type: "get",
			dataType: "json",
			success:
				function(ret)
				{
					if (ret['ack'] == 'success')
					{
						current_tag.parent().parent().prev().html(ret['status_html']);
					}
					else
					{
						alert("修改失败");
					}
				}
		});
	});

	$(".change_purchase_status_click").click(function(){
		var current_tag = $(this);
		var data = current_tag.next().val();
		$.ajax({
			url: "<?=url('DataCenter::Warehouse/UpdateProductPurchaseStatusSingle')?>&data=" + data,
			type: "get",
			dataType: "json",
			success:
				function(ret)
				{
					if (ret['ack'] == 'success')
					{
						current_tag.parent().parent().prev().html(ret['status_html']);
					}
					else
					{
						alert("修改失败");
					}
				}
		});
	});
})
</script>
<style type="text/css">
.more_status {
	position: absolute;
	top: 16px;
	left: 2px;
	width: 55px;
	background-color: #eeeeee;
	z-index: 100;
	display: none;
	border: 1px solid;
}
.change_status_click:hover{cursor: pointer;}
</style>
<fieldset><legend>查询条件</legend>
<form method="get">
<? include(Q::ini('custom_system/elements_dir') . 'searchform_element.php');?>
<table class="form_table">
<tr>
	<th>过往库存</th>
	<td><input type="text" name="pass_date" value="<?=isset($_GET['pass_date'])?$_GET['pass_date']:''?>" class="datepicker" disabled="disabled" /></td>
</tr>
<tr>
	<th>产品生成时间</th>
	<td>
		<input type="text" name="begin_create_time" class="datepicker" value="<?=isset($_GET['begin_create_time']) ? $_GET['begin_create_time'] : ''?>" /> to 
		<input type="text" name="end_create_time" class="datepicker" value="<?=isset($_GET['end_create_time']) ? $_GET['end_create_time'] : ''?>" />
	</td>
</tr>
<tr>
	<th>产品编号</th>
	<td colspan="3"><input type="text" name="product_number" value="<?=isset($_GET['product_number']) ? $_GET['product_number'] : ''?>" /> 输入产品编号后六位例如：000001</td>
</tr>
<tr>
	<th>产品关键字</th>
	<td colspan="3"><input type="text" name="product_name" value="<?=isset($_GET['product_name']) ? $_GET['product_name'] : ''?>" /></td>
</tr>
<tr>
	<th>产品类别</th>
	<td colspan="3"><input type="hidden" name="product_categories_id" id="product_categories_id" /></td>
</tr>
<tr>
	<th>仓库</th>
	<td colspan="3">
		<select name="warehouse_id">
		<option value="">请选择..</option>
		<?foreach ($warehouse as $w):?>
		<option value="<?=$w['id']?>" <?if (isset($_GET['warehouse_id']) && $_GET['warehouse_id'] == $w['id'])echo "selected='selected'"?>><?=$w['name']?></option>
		<?endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<th>可用库存</th>
	<td>
		<select name="available_quantity_operator">
			<option value="">请选择..</option>
			<option value="=" <?if (isset($_GET['available_quantity_operator']) && $_GET['available_quantity_operator'] == '=')echo "selected='selected'"?>>=</option>
			<option value=">=" <?if (isset($_GET['available_quantity_operator']) && $_GET['available_quantity_operator'] == '>=')echo "selected='selected'"?>>>=</option>
			<option value="<=" <?if (isset($_GET['available_quantity_operator']) && $_GET['available_quantity_operator'] == '<=')echo "selected='selected'"?>><=</option>
		</select>
		<input type="text" name="available_quantity" value="<?=isset($_GET['available_quantity']) ? $_GET['available_quantity'] : ''?>" />
	</td>
	<th>实际库存</th>
	<td>
		<select name="actual_quantity_operator">
			<option value="">请选择..</option>
			<option value="=" <?if (isset($_GET['actual_quantity_operator']) && $_GET['actual_quantity_operator'] == '=')echo "selected='selected'"?>>=</option>
			<option value=">=" <?if (isset($_GET['actual_quantity_operator']) && $_GET['actual_quantity_operator'] == '>=')echo "selected='selected'"?>>>=</option>
			<option value="<=" <?if (isset($_GET['actual_quantity_operator']) && $_GET['actual_quantity_operator'] == '<=')echo "selected='selected'"?>><=</option>
		</select>
		<input type="text" name="actual_quantity" value="<?=isset($_GET['actual_quantity']) ? $_GET['actual_quantity'] : ''?>" />
	</td>
</tr>
<tr>
	<th>周销</th>
	<td>
		<select name="weekly_sales_operator">
			<option value="">请选择..</option>
			<option value="=" <?if (isset($_GET['weekly_sales_operator']) && $_GET['weekly_sales_operator'] == '=')echo "selected='selected'"?>>=</option>
			<option value=">=" <?if (isset($_GET['weekly_sales_operator']) && $_GET['weekly_sales_operator'] == '>=')echo "selected='selected'"?>>>=</option>
			<option value="<=" <?if (isset($_GET['weekly_sales_operator']) && $_GET['weekly_sales_operator'] == '<=')echo "selected='selected'"?>><=</option>
		</select>
		<input type="text" name="weekly_sales" value="<?=isset($_GET['weekly_sales']) ? $_GET['weekly_sales'] : ''?>" />
	</td>
	<th>月销</th>
	<td>
		<select name="monthly_sales_operator">
			<option value="">请选择..</option>
			<option value="=" <?if (isset($_GET['monthly_sales_operator']) && $_GET['monthly_sales_operator'] == '=')echo "selected='selected'"?>>=</option>
			<option value=">=" <?if (isset($_GET['monthly_sales_operator']) && $_GET['monthly_sales_operator'] == '>=')echo "selected='selected'"?>>>=</option>
			<option value="<=" <?if (isset($_GET['monthly_sales_operator']) && $_GET['monthly_sales_operator'] == '<=')echo "selected='selected'"?>><=</option>
		</select>
		<input type="text" name="monthly_sales" value="<?=isset($_GET['monthly_sales']) ? $_GET['monthly_sales'] : ''?>" />
	</td>
</tr>
<tr>
	<th>采购状态</th>
	<td colspan="3">
		<?foreach (Q::ini('custom_flag/product_purchase_status') as $ps):?>
		<label><input type="checkbox" name="purchase_status[<?=$ps['value']?>]" value="<?=$ps['value']?>" <?if (isset($_GET['purchase_status'][$ps['value']]) && $_GET['purchase_status'][$ps['value']] == $ps['value'])echo "checked=checked"?> /> <font color="#<?=$ps['color']?>"><?=$ps['name']?></font></label>
		<?endforeach;?>
	</td>
</tr>
<tr>
	<th>销售状态</th>
	<td colspan="3">
		<?foreach (Q::ini('custom_flag/product_sales_status') as $ss):?>
		<label><input type="checkbox" name="sales_status[<?=$ss['value']?>]" value="<?=$ss['value']?>" <?if (isset($_GET['sales_status'][$ss['value']]) && $_GET['sales_status'][$ss['value']] == $ss['value'])echo "checked=checked"?> /> <font color="#<?=$ss['color']?>"><?=$ss['name']?></font></label>
		<?endforeach;?>
	</td>
</tr>
<tr>
	<td></td>
	<td>
		<input type="hidden" name="is_search" value="1" />
		<input type="submit" class="button" value="查询" />
	</td>
	<td><input type="button" class="button" value="更新状态" id="refresh_status" /></td>
	<td><span id="loading_img"></span></td>
	<td>
		<?if (isset($url_arr_json)):?>
		<input type="hidden" value='<?=$url_arr_json?>' />
		<input type="button" class="button" value="请求下载" id="request_download" />
		<?endif;?>
	</td>
	<td><span id="download_loading_img"></span></td>
</tr>
</table>
</form>
</fieldset>
<?if (! empty($product)):?>
<table class="list_table" width="100%">
<tr>
	<th width="70">产品编号</th>
	<th>产品名称</th>
	<th width="60">所在仓库</th>
	<th width="25">备注</th>
	<th width="60">采购状态</th>
	<th width="60">销售状态</th>
	<th width="45">可用</th>
	<th width="45">不可用</th>
	<th width="45">周销</th>
	<th width="45">月销</th>
	<th width="60">待入库数</th>
	<th width="50">重量(g)</th>
</tr>
<?foreach ($product as $p):?>
<tr>
	<td width="80">
		<?=$p['number']?>
		<?if ($p['pic_url']):?>
			<?$pretty_photo_number = 0;?>
			<?foreach ($p['pic_url'] as $pp):?>
			<a rel="pretty_photo[<?=$p['id']?>]" href="<?=$pp?>"><?if(!$pretty_photo_number):?><span class="img_icon"></span><?endif;?></a>
			<?$pretty_photo_number = 1;?>
			<?endforeach;?>
		<?endif;?>
		<?if ($p['sales_trend']):?>
			<span class="<?=Helper_BSS_Normal::getIniOne('product_sales_trend', 'value', $p['sales_trend'], 'icon_class') ?>"></span>
		<?endif;?>
	</td>
	<td align="left"><?=$p['product_basic_name']?></td>
	<td><?=$p['warehouse_name']?></td>
	<td>
		<?if ($p['notes']):?>
		<a class="warehouse_notes_icon" title="产品备注" href="<?=url('DataCenter::Warehouse/ProductNotes', array('id' => $p['product_basic_id']));?>"></a>
		<?endif;?>
	</td>
	<td title="<?=empty($p['last_change_purchase_status_user_name']) ? '系统' : $p['last_change_purchase_status_user_name']?> <?=$p['last_change_purchase_status_time']?>">
		<div style="position: relative;">
		<span class="self_status" style="display: block;"><font color="#<?=Helper_BSS_Normal::getIniOne('product_purchase_status', 'value', $p['purchase_status'], 'color')?>"><?=Helper_BSS_Normal::getIniOne('product_purchase_status', 'value', $p['purchase_status'], 'name')?></font></span>
		<ul class="more_status">
			<?foreach (Q::ini('custom_flag/product_purchase_status') as $ps):?>
			<li>
				<a class="change_purchase_status_click"><font color="#<?=$ps['color']?>"><?=$ps['name']?></font></a>
				<input type="hidden" value="<?=$p['id']?>_<?=$ps['value']?>" />
			</li>
			<?endforeach;?>
		</ul>
		</div>
	</td>
	<td title="<?=empty($p['last_change_sales_status_user_name']) ? '系统' : $p['last_change_sales_status_user_name']?> <?=$p['last_change_sales_status_time']?>">
		<div style="position: relative;">
		<span class="self_status" style="display: block;"><font color="#<?=Helper_BSS_Normal::getIniOne('product_sales_status', 'value', $p['sales_status'], 'color')?>"><?=Helper_BSS_Normal::getIniOne('product_sales_status', 'value', $p['sales_status'], 'name')?></font></span>
		<ul class="more_status">
			<?foreach (Q::ini('custom_flag/product_sales_status') as $ss):?>
			<li>
				<a class="change_sales_status_click"><font color="#<?=$ss['color']?>"><?=$ss['name']?></font></a>
				<input type="hidden" value="<?=$p['id']?>_<?=$ss['value']?>" />
			</li>
			<?endforeach;?>
		</ul>
		</div>
	</td>
	<td><?=$p['available_quantity']?></td>
	<td><?=$p['actual_quantity']-$p['available_quantity']?></td>
	<td><?=$p['weekly_sales']?></td>
	<td><?=$p['monthly_sales']?></td>
	<td><?=$p['purchase_actual_quantity']?></td>
	<td><?=sprintf('%.2f',$p['weight'])?></td>
</tr>
<?endforeach;?>
</table>
<?endif;?>
<?=isset($page) ? $page : ''?>
<?php $this->_endblock();?>